package com.briup.jz.service.impl;

import com.briup.jz.bean.BaseRolePrivilege;
import com.briup.jz.bean.BaseRolePrivilegeExample;
import com.briup.jz.dao.BaseRolePrivilegeMapper;
import com.briup.jz.service.IBaseRolePrivilegeService;
import com.briup.jz.utils.CustomerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BaseRolePrivilegeServiceImpl implements IBaseRolePrivilegeService {
    @Autowired
    private BaseRolePrivilegeMapper baseRolePrivilegeMapper;
    @Override
    public void save(BaseRolePrivilege baseRolePrivilege) throws CustomerException {
        BaseRolePrivilegeExample example = new BaseRolePrivilegeExample();
        BaseRolePrivilegeExample.Criteria criteria = example.createCriteria();
        criteria.andRoleIdEqualTo(baseRolePrivilege.getRoleId());
        criteria.andPrivilegeIdEqualTo(baseRolePrivilege.getPrivilegeId());
        List<BaseRolePrivilege> brps = baseRolePrivilegeMapper.selectByExample(example);
        if(brps.size()>0){
            throw new CustomerException("权限重复添加");
        }
        baseRolePrivilegeMapper.insert(baseRolePrivilege);
    }

    @Override
    public List<BaseRolePrivilege> query() {
        BaseRolePrivilegeExample example = new BaseRolePrivilegeExample();
        return baseRolePrivilegeMapper.selectByExample(example);
    }

    @Override
    public void deleteById(long id) throws CustomerException {
        BaseRolePrivilege baseRolePrivilege = baseRolePrivilegeMapper.selectByPrimaryKey(id);
        if (baseRolePrivilege==null){
            throw new CustomerException("删除的记录不存在");
        }
        baseRolePrivilegeMapper.selectByPrimaryKey(id);

    }
}
